package com.xinqizhi.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.common.utils.PageUtils;
import com.common.utils.R;
import com.xinqizhi.entity.SysUserEntity;
import com.xinqizhi.service.SysUserService;

import com.xinqizhi.vo.SysUser;
import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author Rabit
 * @email lj79490324@gmail.com
 * @date 2019-05-09 00:02:09
 */
@RestController
@RequestMapping("user")
public class SysUserController {
    private final static Logger log = Logger.getLogger(SysUserController.class);
    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户登陆
     * @param user
     * @return
     */
    @RequestMapping("/login")
    @ResponseBody
    public Map login( SysUser user) {
        Map result = new HashMap();
        log.info("-------------" + user.toString() + "登陆");
        result.put("success", true);
        result.put("msg", user.getUsername() + "用户登陆成功");
        return result;
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:sysuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{uid}")
    @RequiresPermissions("generator:sysuser:info")
    public R info(@PathVariable("uid") Integer uid){
			SysUserEntity sysUser = sysUserService.selectById(uid);

        return R.ok().put("sysUser", sysUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:sysuser:save")
    public R save(@RequestBody SysUserEntity sysUser){
			sysUserService.insert(sysUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:sysuser:update")
    public R update(@RequestBody SysUserEntity sysUser){
			sysUserService.updateById(sysUser);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:sysuser:delete")
    public R delete(@RequestBody Integer[] uids){
			sysUserService.deleteBatchIds(Arrays.asList(uids));

        return R.ok();
    }

}
